/*
 * @Copyright: 2017 www.yyfax.com Inc. All rights reserved.
 */
package com.yyfax.pay.order.model.to.auth;

import org.apache.commons.lang3.StringUtils;

import com.yyfax.framework.exception.YYException;
import com.yyfax.framework.yyfax.enums.RspCodeEnum;
import com.yyfax.framework.yyfax.enums.TerminalEnum;
import com.yyfax.pay.common.model.to.YYPayParams;

/**
 * 独立鉴权 —— 直连——发送验证码
 * 
 * @author jiangmy
 * @date 2017-04-11 13:56:44
 * @since v1.0.0
 */
@SuppressWarnings("serial")
public class AuthConfirmDirectParams extends YYPayParams {
	private String userIp; // 用户端请求IP
	private String terminal; // 终端
	private String merchantCode; // 商户编号
	private String userId; // 商户用户ID
	private String orderId; // 商户订单号
	private String idNo;
	private String name;
	private String cardNo;
	private String phone; // 手机号
	private String token;
	private String validCode;

	public String getUserIp() {
		return userIp;
	}

	public void setUserIp(String userIp) {
		this.userIp = userIp;
	}

	public String getTerminal() {
		return terminal;
	}

	public void setTerminal(String terminal) {
		this.terminal = terminal;
	}

	public String getMerchantCode() {
		return merchantCode;
	}

	public void setMerchantCode(String merchantCode) {
		this.merchantCode = merchantCode;
	}

	public String getUserId() {
		return userId;
	}

	public void setUserId(String userId) {
		this.userId = userId;
	}

	public String getOrderId() {
		return orderId;
	}

	public void setOrderId(String orderId) {
		this.orderId = orderId;
	}

	public String getIdNo() {
		return idNo;
	}

	public void setIdNo(String idNo) {
		this.idNo = idNo;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getCardNo() {
		return cardNo;
	}

	public void setCardNo(String cardNo) {
		this.cardNo = cardNo;
	}

	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	public String getToken() {
		return token;
	}

	public void setToken(String token) {
		this.token = token;
	}

	public String getValidCode() {
		return validCode;
	}

	public void setValidCode(String validCode) {
		this.validCode = validCode;
	}

	@Override
	public boolean validate() throws Exception {
		if (StringUtils.isBlank(this.userIp)) {
			throw new YYException(RspCodeEnum.COMMON_ERROR_PARAMETER_INVALID, "'userIp'不能为空");
		}

		if (StringUtils.isBlank(this.terminal) && !TerminalEnum.IOS.isValue(this.terminal) && !TerminalEnum.ANDROID.isValue(this.terminal)) {
			throw new YYException(RspCodeEnum.COMMON_ERROR_PARAMETER_INVALID, "'terminal'不能为空，或者不支持的终端类型");
		}

		if (StringUtils.isBlank(this.merchantCode)) {
			throw new YYException(RspCodeEnum.COMMON_ERROR_PARAMETER_INVALID, "'merchantCode'不能为空");
		}

		if (StringUtils.isBlank(this.userId)) {
			throw new YYException(RspCodeEnum.COMMON_ERROR_PARAMETER_INVALID, "'userId'不能为空");
		}

		if (StringUtils.isBlank(this.orderId) || this.orderId.length() > 14) {
			throw new YYException(RspCodeEnum.COMMON_ERROR_PARAMETER_INVALID, "'orderId'不能为空/长度不能超过13位");
		}

		if (StringUtils.isBlank(this.token)) {
			throw new YYException(RspCodeEnum.COMMON_ERROR_PARAMETER_INVALID, "'token'不能为空");
		}

		if (StringUtils.isBlank(this.validCode)) {
			throw new YYException(RspCodeEnum.COMMON_ERROR_PARAMETER_INVALID, "'validCode'不能为空");
		}

		if (StringUtils.isBlank(this.phone)) {
			throw new YYException(RspCodeEnum.COMMON_ERROR_PARAMETER_INVALID, "'phone'不能为空");
		}

		if (StringUtils.isBlank(this.idNo)) {
			throw new YYException(RspCodeEnum.COMMON_ERROR_PARAMETER_INVALID, "'idNo'不能为空");
		}

		if (StringUtils.isBlank(this.name)) {
			throw new YYException(RspCodeEnum.COMMON_ERROR_PARAMETER_INVALID, "'name'不能为空");
		}

		if (StringUtils.isBlank(this.cardNo)) {
			throw new YYException(RspCodeEnum.COMMON_ERROR_PARAMETER_INVALID, "'cardNo'不能为空");
		}

		return true;
	}

	@Override
	public String[] signFields() {
		return new String[] { "userIp", "terminal", "merchantCode", "userId", "orderId", "idNo", "name", "cardNo", "phone", "token", "validCode" };
	}
}
